package pack01;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.Test;

import java.net.URI;

/**
 * @author lilulu
 * @date 2023/2/9 23:37
 */
public class hdfsDemo01 {


    //1:获取FileSystem对象
    @Test
    public void getFileSystem() throws Exception {
        FileSystem fileSystem = FileSystem.get(new URI("hdfs://node1:8020"), new Configuration());
        System.out.println(fileSystem);
    }


    //2:在HDFS上创建目录
    @Test
    public void mkdirTest() throws Exception{
        FileSystem fileSystem = FileSystem.get(new URI("hdfs://node1:8020"), new Configuration());
        //创建目录
        fileSystem.mkdirs(new Path("/xxx/yyy/zzz")); //写权限

        //关闭文件系统
        fileSystem.close();
    }

    //3:删除目录
    @Test
    public void deleteTest() throws Exception{
        FileSystem fileSystem = FileSystem.get(new URI("hdfs://node1:8020"), new Configuration());
        //删除目录
        fileSystem.delete(new Path("/xxx"),true);

        //关闭文件系统
        fileSystem.close();
    }

}
